//---------------------------------------------------------------------
// File: Exceptions.cs
// 
// Summary: Defines custom exceptions thrown by all 
//          classes and contains function for retrieving
//          exception strings
//
//
//---------------------------------------------------------------------
// This file is part of the Microsoft ESB Guidance for BizTalk
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// This source code is intended only as a supplement to Microsoft BizTalk
// Server 2006 R2 release and/or on-line documentation. See these other
// materials for detailed information regarding Microsoft code samples.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
// PURPOSE.
//---------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Resources;
using System.Reflection;
using System.Collections.Specialized;
using System.Runtime.Serialization;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using System.Diagnostics;

namespace Microsoft.Practices.ESB.Exception.Management
{
      
    /// <summary>
    /// Summary description for ExceptionMessage.
    /// </summary>
    /// 
    internal static class Exceptions
    {
        #region Constants
        /// <summary>
        /// Error codes passed to custom Exceptions and used to look up
        /// descriptions in resource file
        /// </summary>

        public const string ResourceBaseName = "Microsoft.Practices.ESB.Exception.Management.Exceptions";
        public const int FaultExceptionMessage = 854000;
        public const int SoapExceptionMessage = 854001;
        

        #endregion

        /// <summary>
        /// looks up exceptions descriptions based on error codes. prepends "e"
        /// for lookup in resource file. Calls ResourceStringLoader.GetErrorDescription()
        /// </summary>
        /// <param name="errorCode">code represented by constant</param>
        /// <returns>string representing error code</returns>
        internal static string GetErrorDescription(int errorCode)
        {
            try
            {
                string message = ResourceStringLoader.GetErrorDescription(errorCode,
                    Exceptions.ResourceBaseName, Assembly.GetExecutingAssembly());

                return message;
            }
            catch (System.Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// looks up exceptions descriptions based on error codes. prepends "e"
        /// for lookup in resource file
        /// </summary>
        /// <param name="errorCode">code represented by constant</param>
        /// <param name="arguments">optional arguments to format in message</param>
        /// <returns>string representing error code</returns>
        internal static string GetErrorDescription(int errorCode,
            params Object[] arguments)
        {
            try
            {
                string message = ResourceStringLoader.GetErrorDescription(errorCode,
                    Exceptions.ResourceBaseName, Assembly.GetExecutingAssembly());
                return string.Format(CultureInfo.CurrentCulture, message, arguments);
            }
            catch (System.Exception)
            {
                throw;
            }
        }
    }
    
    
}
